package web.beans;

import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

import ejb.dto.EscursioneDTO;
import ejb.dto.HotelDTO;
import ejb.dto.PacchettoDTO;
import ejb.dto.ProdottoBaseDTO;
import ejb.dto.UserDTO;
import ejb.dto.VoloDTO;
import ejb.managerbeans.PackManagerBeanLocal;
import ejb.managerbeans.ProdottoManagerBeanLocal;

@ManagedBean(name = "buyBean")
@SessionScoped
public class BuyBean {

	@EJB
	private ProdottoManagerBeanLocal pbMgr;

	@EJB
	private PackManagerBeanLocal packMgr;

	private String addedProd = "";

	private String searchedProd;

	private UserDTO user;
	private ProdottoBaseDTO prodottoBase;

	private VoloDTO volo;
	private HotelDTO hotel;
	private EscursioneDTO escursione;
	private PacchettoDTO pacchetto;

	private int guests;

	@PostConstruct
	public void init() {

		user = new UserDTO();
		prodottoBase = new ProdottoBaseDTO();

	}

	

	public String getAddedProd() {
		return addedProd;
	}

	public void setAddedProd(String addedProd) {
		this.addedProd = addedProd;
	}

	public String getSearchedProd() {
		return searchedProd;
	}

	public void setSearchedProd(String searchedProd) {
		this.searchedProd = searchedProd;
	}

	public VoloDTO getVolo() {
		return volo;
	}

	public void setVolo(VoloDTO volo) {
		this.volo = volo;
	}

	public HotelDTO getHotel() {
		return hotel;
	}

	public void setHotel(HotelDTO hotel) {
		this.hotel = hotel;
	}

	public EscursioneDTO getEscursione() {
		return escursione;
	}

	public void setEscursione(EscursioneDTO escursione) {
		this.escursione = escursione;
	}

	public PacchettoDTO getPacchetto() {
		return pacchetto;
	}

	public void setPacchetto(PacchettoDTO pacchetto) {
		this.pacchetto = pacchetto;
	}

	public int getGuests() {
		return guests;
	}

	public void setGuests(int guests) {
		this.guests = guests;
	}

	public UserDTO getUser() {
		return user;
	}

	public void setUser(UserDTO user) {
		this.user = user;
	}

	/**
	 * acquisto voli
	 */
	public void buyVolo() {
		prodottoBase.setId(volo.getId());
		buyBasicProduct();
	}

	/**
	 * acquisto hotels
	 */
	public void buyHotel() {
		prodottoBase.setId(hotel.getId());
		buyBasicProduct();
	}

	/**
	 * acquisto escursioni
	 */
	public void buyEscursione() {
		prodottoBase.setId(escursione.getId());
		buyBasicProduct();
	}

	/**
	 * acquisto pacchetti
	 */
	public void buyPacchetto() {
		pacchetto.setId(pacchetto.getId());
		buyPack();
	}

	private void buyBasicProduct() {

		pbMgr.boughtBasicProduct(prodottoBase, user);
	}

	private void buyPack() {

		packMgr.boughtPack(pacchetto);
	}

}
